<template>
  <div>
    <div class="develop" ref="develop"></div>
  </div>
</template>


<script>
import * as echarts from "echarts";
export default {
  data() {
    return {};
  },
  mounted() {
    // 绘制产业增加值 图
    this.drawDevelop();
  },
  methods: {
    // 绘制产业增加值 图
    drawDevelop() {
      // 用于清除定时器
      let tootipTimer = null;
      let develop = echarts.init(this.$refs.develop);
      let option0 = {
        legend: {
          top: "25",
          formatter: "{name}",
          textStyle: {
            color: "#333",
            fontWeight: 400,
            fontFamily: "Microsoft YaHei",
            fontSize: 16,
          },
          icon: "rect",
        },
        tooltip: {
          trigger: "axis",
        },
        // toolbox: {
        //   show: true,
        //   feature: {
        //     // dataView: { show: true, readOnly: false },
        //     magicType: { show: true, type: ["line", "bar"] },
        //     restore: { show: true },
        //     saveAsImage: { show: true },
        //   },
        // },
        calculable: true,
        dataset: {
          source: [
            ["product", "2017", "2018", "2019", "2020"],
            ["第二产业增加值", 14, 15.3, 17.1, 19.0],
            ["第三产业增加值", 25.5, 29.6, 35.1, 37.2],
            ["固定资产投资额", 58.1, 67.4, 78.5, 84.0],
            ["社会消费品零售总额", 15.8, 17.5, 19.2, 20.3],
          ],
        },
        xAxis: {
          axisLine: {
            lineStyle: {
              color: "#0D52AC",
              with: 3,
            },
          },
          type: "category",
          nameLocation: "center",
          axisTick: {
            alignWithLabel: true,
          },
          axisLabel: {
            color: "#333",
            fontFamily: "Microsoft YaHei",
            fontWeight: 400,
            fontSize: 16,
          },
        },
        yAxis: {
          show: false,
        },
        grid: {
          left: "-5%",
          right: "10%",
          top: "25%",
          bottom: "0%",
          containLabel: true,
        },
        series: [
          {
            type: "line",
            smooth: true,
            seriesLayoutBy: "row",
            symbol: "none",
            color: "#00FFE9",
          },
          {
            type: "line",
            smooth: true,
            seriesLayoutBy: "row",
            symbol: "none",
          },
          {
            type: "line",
            smooth: true,
            seriesLayoutBy: "row",
            symbol: "none",
            color: "#00FF00",
          },
          {
            type: "line",
            smooth: true,
            seriesLayoutBy: "row",
            symbol: "none",
            color: "#FF00B2",
          },
        ],
      };
      // 3,绘图
      develop.setOption(option0);
      // 可调用clearLoop方法，清除定时器
      tootipTimer && tootipTimer.clearLoop();
      tootipTimer = null;
      // 调用轮播的方法
      tootipTimer = tools.loopShowTooltip(develop, option0, {
        interval: 1000, // 轮播间隔时间
        loopSeries: true, // 是否开启轮播循环
      });
    },
  },
};
</script>

<style scoped>
.develop {
  width: 100%;
  height: 300px;
}
</style>